home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------
-
- CScreenSaverWindow.cpp
-
- Window for drawing in from a plugin.
-
- ---------------------------------------------------------------*/
-
- #include "CScreenSaverWindow.h"
- #include "CPluginManager.h"
- #include "IPluginDrawIntf.h"
- #include "HideShowMbar.h"
- #include <UWindows.h>
-
- extern CPluginManager* gPluginManager;
-
-
- CScreenSaverWindow::CScreenSaverWindow( LStream* inStream )
- :LWindow( inStream ), mPlugin(0)
- {
- mPlugin = gPluginManager->GetCurrentPlugin();
- if ( mPlugin->Load() == noErr ) {
-
- mPlugin->GetInterfacePointer(IPluginDraw_ID, &mDrawIntf );
-
- SetUpWindow();
-
- Rect theRect;
- CalcLocalFrameRect( theRect );
- mDrawIntf->Initialize();
- mDrawIntf->SetDrawingRect( theRect );
-
-
-
- StartRepeating();
- } else {
- throw;
- }
- }
-
- void CScreenSaverWindow::SetUpWindow()
- {
- // resize the window to the whole screen
- GDHandle dominantDevice = UWindows::FindDominantDevice(
- UWindows::GetWindowStructureRect(GetMacPort()));
-
- if (dominantDevice == nil) { // Window is offscreen, so use the
- // main scren
- dominantDevice = ::GetMainDevice();
- }
- Rect screenRect = (**dominantDevice).gdRect;
- MoveWindowTo(0,0);
- ResizeWindowTo( screenRect.right - screenRect.left,
- screenRect.bottom - screenRect.top );
-
- // Hide the menu bar
- HideShowMBAR( eHide );
-
- }
-
- CScreenSaverWindow::~CScreenSaverWindow()
- {
- FocusDraw();
- mDrawIntf->Terminate();
-
- if ( mPlugin->IsLoaded() ) { // how could it be anything else
- mPlugin->Unload();
- }
-
- // show the menu bar
- HideShowMBAR( eShow );
-
- }
-
- Boolean
- CScreenSaverWindow::HandleKeyPress(
- const EventRecord &inKeyEvent)
- {
- // close the window
- DoClose();
- return true;
- }
-
- void
- CScreenSaverWindow::ClickSelf(const SMouseDownEvent &inMouseDown)
- {
- // close the window
- DoClose();
- }
-
- void
- CScreenSaverWindow::DrawSelf()
- {
- Rect theRect;
- CalcLocalFrameRect( theRect );
- mDrawIntf->SetDrawingRect( theRect );
- }
-
- void CScreenSaverWindow::SpendTime( const EventRecord &inMacEvent )
- {
- FocusDraw();
- mDrawIntf->DrawFrame();
- }
-